#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    int t, x, y;
    cin >> t;
    while (t--) {
        cin >> x >> y;
        if (y % x)
            cout << "0 0" << endl;
        else if (x == y) {
            cout << "1 1" << endl;
        } else {
            int c = y/x, flag = 0;
            for (int b = 2; b <= c; b++) {
                int a = 1, d = b;
                while(d < c) {
                    d *= b, a++;
                }
                if (d == c) {
                    cout << a << ' ' << b << endl;
                    flag = 1;
                    break;
                }
            }
            if (!flag) cout << "0 0" << endl;
        }
    }
    return 0;
}